package com.atguigu.controller;

import com.atguigu.entity.HouseUser;
import com.atguigu.service.HouseUserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.checkerframework.checker.units.qual.C;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/houseUser")
public class HouseUserController {

    @DubboReference
    private HouseUserService houseUserService;

    /*进入新增视图*/
    @RequestMapping("/create")
    public String create(Long houseId, ModelMap map){
        map.put("houseId",houseId);
        return "houseUser/create";
    }
    /*保存房东信息*/
    @RequestMapping("/save")
    public String save(HouseUser houseUser){
        houseUserService.insert(houseUser);
        return "common/successPage";
    }
    /*进入编辑视图
    **/
    @RequestMapping("/edit/{id}")
    public String edit(@PathVariable("id")Long id,ModelMap map){
        HouseUser houseUser = houseUserService.getById(id);
        map.put("houseUser",houseUser);
        return "houseUser/edit";
    }

    /*保存修改*/
    @RequestMapping("/update")
    public String update(HouseUser houseUser){
        houseUserService.update(houseUser);
        return "common/successPage";
    }
    /*删除房东*/
    @RequestMapping("/delete/{houseId}/{id}")
    public String delete(
            @PathVariable("houseId") Long houseId,
            @PathVariable("id") Long id
    ){
        houseUserService.delete(id);
        return "redirect:/house/"+houseId;

    }

}
